import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import path from 'path'
import Unocss from 'unocss/vite'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
    // https://github.com/antfu/unocss
    Unocss(),
    Components({
      resolvers: [VantResolver()]
    })
  ],
  server: {
    // port: 8000,
    // host: '0.0.0.0',
    proxy: {
      '/api/': {
        // target: 'http://phoneapi.songzi-it.com/',
        target: 'https://api.blacksilverscore.com',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/api/, '')
      },
      '/api-prod/': {
        // target: 'http://phoneapi.songzi-it.com/',
        // target: 'https://250a7c9202.imdo.co',
        target: 'https://api.blacksilverscore.com',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/api-prod/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components')
    }
  },
  css: {
    // 配置`scss`和`less`全局变量
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/vars/_base.scss";'
      },
      less: {
        additionalData: '@import "@/styles/vars/_base.less";'
      }
    }
  },
  base: '/',
  build: {
    assetsDir: 'assets',
    outDir: 'hyLife',
    rollupOptions: {
      external: ['wz_location.min.js'],
      output: {
        globals: {
          'wz_location.min.js': 'WzLocation'
        }
      }
    }
  }
})
